package com.yi.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器实现
 * @author YI
 * @date 2018-3-15 16:56:59
 */
public class SessionHandlerInterceptor implements HandlerInterceptor {
    /**
     * 用于访问请求拦截
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception{
        System.out.println("访问接口为：" + request.getRequestURI());
        return true;
    }

    /**
     * Controller 方法处理完毕调用此方法
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception{
//        System.out.println("Controller 方法处理完毕调用此方法");
    }

    /**
     * 页面处理完调用此方法，通常用来清除某些资源，类似Java中的finally
     * @param request
     * @param response
     * @param handler
     * @param ex
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
//        System.out.println("页面处理完调用此方法，通常用来清除某些资源，类似Java中的finally");
    }
}
